#!/usr/env/bin python
# -*- coding: utf-8 -*-
# filename: 字谜分组.py
# creator: yangdy
# create date: 2018/3/19
"""  
字谜分组
"""

from collections import defaultdict

class mystr(str):
   def sort(self):
      a = list(self)
      a.sort()
      return ''.join(a)

def main():
   strs = ["eat","tea","tan","ate","nat","bat"]
   m = defaultdict(lambda : None)
   for s in strs:
       so = mystr(s).sort()
       if m[so]:
           m[so].append(s)
       else:
           m[so] = [s]
   ans = []
   for k in m:
       ans.append(m[k])
   print(ans)


if __name__=='__main__':
    main()